#if !defined( __TF_MODULES_H__)
#define __TF_MODULES_H__

#include "TFstd.h"

#if defined ( __WINDOWS_PLATFORM__)
#   include <windows.h>
#elif defined ( __GNU_PLATFORM__)
#   include <unistd.h>
#endif

// Dynamic module macroes
#if defined( TF_EXPORT )
#undef TF_EXPORT
#endif

#if defined( TF_IMPORT )
#undef TF_IMPORT
#endif

#if defined ( __WINDOWS_PLATFORM__)
#define TF_EXPORT __declspec(dllexport)
#define TF_IMPORT __declspec(dllimport)
#elif defined ( __GNU_PLATFORM__)
#define TF_EXPORT
#define TF_IMPORT
#endif

//Choose propriate dynamic library export/import
#if defined ( TF_LIB_EXPORT)
#define TF_API TF_EXPORT
#else
#define TF_API TF_IMPORT
#endif

namespace tagfolder{

    /**
     *  Class to deal with dynamic modules loading and using
     *
     */
    class TFModule{
        public:
#if defined( __WINDOWS_PLATFORM__)
            typedef HMODULE ModuleHandler;
#else
            typedef void* ModuleHandler;
#endif
        public:
            TFModule();
            TFModule(const char* fileName);
            virtual ~TFModule();
            virtual void* getSymbolAddress( const char* symbolName);
            virtual bool load();
            virtual bool load( const char* moduleName);
            virtual bool close( );
            bool isClosed() const;
            const char* getModuleName() const;
            ModuleHandler getModuleHandler() const;
        protected:
            static ModuleHandler loadModule( const char* fileName);
            static void* parseSymbol( ModuleHandler handler, const char* symbolName);
            static bool closeModule( ModuleHandler handler);
        private:
            TFModule( TFModule&){}
            TFModule& operator=( TFModule&) { return (*this);}
        private:
            ModuleHandler m_Handler;
            char* m_fileName;
            bool m_closed;
    };
}

#endif // #if !defined( __TF_MODULES_H__)
